<template>
  <div class="checkPlan_box">
    <div class="checkPlan_top">
      <div class="checkPlan_title">财务状况</div>
    </div>

    <div v-if="cause&&cause.length>0" class="echarts_container">
      <div id="reasonOne" class="col-md-12  col-sm-12 col-xs-12" style="height: 100%;" />
    </div>
    <div v-else class="echarts_noData">
      <svg-icon icon-class="暂无数据" />
    </div>
  </div>
</template>

<script>
import { situation } from '@/api/receivableAndPayable/receivableAndPayableManage/receivableBoard'
import { mapGetters } from 'vuex'
export default {
  name: 'LocationDistribution',
  computed: {
    ...mapGetters([
      'windowResizeTag'
    ])
  },
  watch: {
    windowResizeTag() {
      if (this.myChart) {
        this.$nextTick(() => {
          setTimeout(() => {
            this.drawLine()
          }, 500)
        })
      }
    }
  },
  data() {
    return {
      msg: 'fafa',
      cause: ['1'],
      value: '1',
      myChart: undefined,
      myVertical: undefined,
      timer: undefined
    }
  },
  beforeDestroy() {
    // 页面关闭清除定时器
    clearInterval(this.timer)
  },
  mounted() {
    // this.drawLine()
    this.getList()
    this.timer = setInterval(() => {
      this.getList()
    }, this.$store.state.common.refreshFrequency * 1000)
    // this.getValue()
  },
  methods: {
    getList() {
      situation().then(res => {
        this.cause = res.data
        this.drawLine()
      })
    },
    drawLine() {
      if (this.myChart) {
        this.$echarts.init(document.getElementById('reasonOne')).dispose()
      }

      this.myChart = this.$echarts.init(document.getElementById('reasonOne'))
      this.myChart.setOption({
        grid: {
          show: false,
          top: '40',
          right: '20',
          bottom: '40',
          left: '80'
        },
        tooltip: {
          trigger: 'axis',
          padding: [12, 17, 20, 23],
          textStyle: { color: '#333' },
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          left: 'right',
          padding: [0, 20, 0, 0],
          itemGap: 50
        },
        axisLabel: {
          show: true,
          color: '#999999', // 更改坐标轴文字颜色
          textStyle: {
            fontSize: 12 // 更改坐标轴文字大小
          }
        },
        yAxis: {
          type: 'value',
          // 影藏y轴刻度
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            },
            margin: 20
          }
        },
        color: ['#B96F8E', '#0DA5BC'],
        dataset: {
          dimensions: ['product', '本月实付', '本月实收'],
          source: this.cause
        },
        xAxis: { type: 'category' },
        barWidth: '12',
        label: {
          show: false,
          position: 'top',
          color: '#333333',
          fontSize: 12
        },
        series: [{ type: 'bar' }, { type: 'bar' }]
      })
    }
  }
}
</script>

<style lang="less" scoped>
.checkPlan_box{
  width: 100%;
  height: calc(100% - 50px);
}
.checkPlan_top {
  display: flex;
  justify-content: space-between;

  .checkPlan_title {
    font-size: 20px;
    font-weight: bold;
    line-height: 34px;
    letter-spacing: -0.21px;
    color: #333333;
    padding-top: 16px;
    padding-left: 20px;
  }

  .checkPlan_month{
    padding-top: 16px;
    padding-right: 20px;
  }
}
</style>
